Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: QuickTime Components

Previous | Overview | Contents | Next |

Using the Callback Functions

Applications that use QuickTime time bases may define callback functions that are associated with a specific time base. Applications can then use these callback functions to perform activities that are triggered by temporal events, such as a certain time being reached or a specified rate being achieved. The time base functions of the Movie Toolbox interact with clock components to schedule the invocation of these callback functions--your clock component is responsible for calling the callback function at its scheduled time.

The functions described in this section are called by the Movie Toolbox to support applications that define time base callback functions. For more information about time base callback functions, see the chapter "Movie Toolbox" in Inside Macintosh: QuickTime . Note that your clock component can delegate its callback events to another component by calling the Component Manager's DelegateComponent function, which is described in the chapter "Component Manager" in Inside Macintosh: More Macintosh Toolbox .

The ClockNewCallBack function allows your clock component to allocate the memory to support a new callback event. When an application discards a callback event, the Movie Toolbox calls your clock component's ClockDisposeCallBack function.

The Movie Toolbox calls your clock component's ClockCallMeWhen function when an application wants to schedule a callback event. When the callback function is to be invoked to service the event, the Movie Toolbox calls your component's ClockCancelCallBack function so that you can remove the callback event from the list of scheduled events.

ClockNewCallBack

Your component's ClockNewCallBack function allocates the memory for a new callback event. The Movie Toolbox calls this function when an application defines a time base callback event with the Movie Toolbox's NewCallBack function. The callback event created at this time is not active until it has been scheduled. An application schedules a callback event by calling the Movie Toolbox's CallMeWhen function.

Your component allocates the memory required to support the callback event. The memory must be in a locked block and must begin with a callback header structure. This structure is described in "Data Type," which begins on Data Type .

You should not call this function at interrupt time.

pascal QTCallBack ClockNewCallBack (ComponentInstance aClock,
                                         TimeBase tb,
                                         short callBackType);

aClock
Specifies the clock for the operation. Applications obtain this identifier from the Component Manager's OpenComponent function.

tb
Specifies the callback event's time base. Typically, your component does not need to save this specification. You can use the Movie Toolbox's GetCallBackTimeBase function to determine the callback event's time base when it is invoked (see the discussion of time bases in the chapter "Movie Toolbox" in Inside Macintosh: QuickTime for more information about this function).

callBackType
Specifies when the callback event is to be invoked. The value of this field governs how your component interprets the data supplied in the param1 , param2 , and param3 parameters to the ClockCallMeWhen function, which is described in the next section. The following three values are valid for this parameter:

callBackAtTime
Indicates that the callback event is to be invoked at a specified time. The Movie Toolbox supplies this time to your component in the parameter data of the ClockCallMeWhen function (described in the next section).

callBackAtRate
Indicates that the callback event is to be invoked when the rate for the time base reaches a specified value. The Movie Toolbox supplies this value to your component in the parameter data of the ClockCallMeWhen function.

callBackAtTimeJump
Indicates that the callback event is to be invoked when a program changes the time value for the time base.

In addition, if the high-order bit of the callBackType parameter is set to 1 (this bit is defined by the callBackAtInterrupt flag), the callback event may be invoked at interrupt time.

DESCRIPTION

Your clock component allocates the memory for the event and returns a pointer to that memory. If your clock component cannot satisfy the request or detects invalid or unsupported parameter values, you should set the QTCallBack result to nil .

Your component can allocate an arbitrarily large piece of memory for the callback event. That memory must begin with a callback header structure, which must be initialized to 0.

ClockCallMeWhen

Your clock component's ClockCallMeWhen function schedules a callback event for invocation. The Movie Toolbox calls this function when an application schedules a callback event using the CallMeWhen function of the Movie Toolbox (described in the chapter "Movie Toolbox" in Inside Macintosh: QuickTime ).

The Movie Toolbox passes the parameter data from its CallMeWhen function to your component in the param1 , param2 , and param3 parameters to this function. Your clock component interprets these parameters based on the value of the callBackType parameter to the ClockNewCallBack function (see ClockNewCallBack ).

pascal ComponentResult ClockCallMeWhen (ComponentInstance aClock,
                                          QTCallBack cb,
                                         long param1,
                                         long param2,
                                         long param3);

aClock
Specifies the clock for the operation. Applications obtain this identifier from the Component Manager's OpenComponent function.

cb
Specifies the callback event for the operation. The Movie Toolbox obtains this value from your component's ClockNewCallBack function.

param1
Contains data supplied to the Movie Toolbox in the param1 parameter to the CallMeWhen function. Your component interprets this parameter based on the value of the callBackType parameter to the ClockNewCallBack function.

If callBackType is set to callBackAtTime , param1 contains QuickTime callback flags indicating when to invoke the callback function. The following values are defined:

triggerTimeFwd
Indicates that the callback function should be called at the time specified by param2 only when time is moving forward (positive rate). The value of this flag is 0x0001.

triggerTimeBwd
Indicates that the callback function should be called at the time specified by param2 only when time is moving backward (negative rate). The value of this flag is 0x0002.

triggerTimeEither
Indicates that the callback function should be called at the time specified by param2 without regard to direction. The value of this flag is 0x0003.

If callBackType is set to callBackAtRate , param1 contains flags indicating when to invoke the callback function.

The following values are defined:

triggerRateChange
Indicates that the callback function should be called whenever the rate changes. The value of this flag is 0.

triggerRateLT
Indicates that the callback function should be called when the rate changes to a value less than that specified by param2 . The value of this flag is 0x0004.

triggerRateGT
Indicates that the callback function should be called when the rate changes to a value greater than that specified by param2 . The value of this flag is 0x0008.

triggerRateEqual
Indicates that the callback function should be called when the rate changes to a value equal to that specified by param2 . The value of this flag is 0x0010.

triggerRateLTE
Indicates that the callback function should be called when the rate changes to a value that is less than or equal to that specified by param2 . The value of this flag is 0x0014.

triggerRateGTE
Indicates that the callback function should be called when the rate changes to a value that is less than or equal to that specified by param2 . The value of this flag is 0x0018.

triggerRateNotEqual
Indicates that the callback function should be called when the rate changes to a value that is not equal to that specified by param2 . The value of this flag is 0x001C.

param2
Contains data supplied to the Movie Toolbox in the param2 parameter to the CallMeWhen function (see ClockCallMeWhen ). Your component interprets this parameter based on the value of the callBackType parameter to the ClockNewCallBack function, described on ClockNewCallBack .

If callBackType is set to callBackAtTime , param2 contains the time value at which your component should invoke the callback function for this event. The param1 parameter contains flags affecting when you should call the function.

If callBackType is set to callBackAtRate , param2 contains the rate value at which your component should invoke the callback function for this event. The param1 parameter contains flags affecting when you should call the function.

param3
Contains data supplied to the Movie Toolbox in the param3 parameter to the CallMeWhen function. If qtType is set to callBackAtTime , param3 contains the time scale in which to interpret the time value that is stored in param2 .

DESCRIPTION

The Movie Toolbox maintains control information about the callback event. Your clock component only needs to maintain the invocation schedule. For example, the Movie Toolbox saves the address of the callback event, its reference constant, and the value of the A5 register. In addition, the Movie Toolbox prevents applications from scheduling a single callback event more than once.

If your clock component successfully schedules the callback event, you should call the AddCallBackToTimeBase function (described on AddCallBackToTimeBase ) to add it to the list of callback events for the corresponding time base. If your component cannot schedule the callback event, it should return an appropriate error.

ClockCancelCallBack

Your clock component's ClockCancelCallBack function removes the specified callback event from the list of scheduled callback events for a time base.

pascal ComponentResult ClockCancelCallBack
                                         (ComponentInstance aClock,
                                          QTCallBack cb);

aClock
Specifies the clock for the operation. Your application obtains this identifier from the Component Manager's OpenComponent function.

cb
Specifies the callback event for the operation. The Movie Toolbox obtains this value from your component's ClockNewCallBack function (described on ClockNewCallBack ).

DESCRIPTION

The Movie Toolbox calls this function when an application cancels its callback event by calling CancelCallBack . The Movie Toolbox also calls this function whenever it executes the callback event, thus removing it from the list of scheduled callback events. The application is then responsible for rescheduling the event, if appropriate.

If your clock component successfully cancels the callback event, you should call the RemoveCallBackFromTimeBase function, described on RemoveCallBackFromTimeBase , so that the Movie Toolbox can remove the callback event from its list of scheduled events.

ClockDisposeCallBack

Your clock component's ClockDisposeCallBack function disposes of the memory associated with the specified callback event.

pascal ComponentResult ClockDisposeCallBack
                                         (ComponentInstance aClock,
                                          QTCallBack cb);

aClock
Specifies the clock for the operation. Applications obtain this identifier from the Component Manager's OpenComponent function.

cb
Specifies the callback event for the operation. The Movie Toolbox obtains this value from your component's ClockNewCallBack function (described on ClockNewCallBack ).

DESCRIPTION

The Movie Toolbox calls this function when an application discards its callback event by calling the DisposeCallBack function. Your clock component should cancel the callback event before you dispose of it.

You should not call this function at interrupt time.


© 1999 Apple Computer, Inc.

Previous | Overview | Contents | Next